package club.hicode.daydayup.kafka;

import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;

/**
 * Kafka的发送者
 *
 * @author Liu Chunfu
 * @date 2018-07-25 上午10:42
 **/
@Component
public class KafkaSender {
    @Autowired
    private KafkaTemplate kafkaTemplate;


    public void sendMessage() {
        MicMessage m = new MicMessage();
        m.setId(System.currentTimeMillis());
        m.setMsg(UUID.randomUUID().toString());
        m.setSendTime(new Date());
        kafkaTemplate.send("test1", JSONUtil.toJsonStr(m));
    }

}
